<template>
	<view class="p-50 p-t-30 left">
		<text class="ts-50 tb left m-b-50">
			<text class="tc-green">系统设置</text>
		</text>
		<br>
		<view class="form-item left" @click="passWord()">
			<view class="form-view">
				<text class="tc-gray">设置密码</text>
				<img src="/static/img/user/right.png" alt="SVG Icon" class="menu-item-icon" />
			</view>
		</view>
		<!-- <view class="form-item left">
			<view class="form-view tc-gray">
				<text>绑定微信</text>
				<text class="form-text tc-green">去绑定</text>
			</view>
		</view> -->
		<view class="form-item left" @click="editPhone()">
			<view class="form-view">
				<text class="tc-gray">更换绑定手机号</text>
				<img src="/static/img/user/right.png" alt="SVG Icon" class="menu-item-icon" />
			</view>
		</view>
		<!-- <view class="form-item left">
			<view class="form-view tc-gray">
				<text>清除缓存</text>
				<text class="form-text tc-green">2.23M</text>
			</view>
		</view> -->
		<view class="form-item left" @click="see(2)">
			<view class="form-view">
				<text class="tc-gray">推送开关</text>
				<switch :checked="push_status === 1" @change="switchChange" color="#005650" class="menu-item-icon" style="transform:scale(0.7); margin-top: 0rpx; margin-right: -30rpx !important;"/>
			</view>
		</view>
		<view class="form-submit left" @click="logout()">
			退出登录
		</view>
	</view>
</template>

<script>
import { mapActions } from 'vuex';
	export default {
		
		data() {
			return {
				checked: true,
				push_status: 1,
			}
		},
		onLoad() {
			this.$xyfun.setNavBar(' ');
			this.getUserInfo().then(res => {
				this.push_status = Number(res.userInfo.push_status)
			}).catch(e => {
				console.log(e);
			});
		},
		methods: {
			...mapActions('user',{'getUserInfo':'getInfo'}),
			logout(){
				uni.showModal({
					title: '退出登录',
					content: '请确认是否退出登录？',
					success: res => {
						if (res.confirm) {
							this.$api.post({
								url: '/user/user/logout',
								success: () => {
									this.$store.dispatch('user/logout');
									this.$xyfun.msg('退出成功');
									uni.navigateTo({
										url:'/pages/user/login'
									})
								}
							});
						}
					}
				})
			},
			switchChange(event) {
				this.$api.post({
					url: '/user/user/profile',
					loadingTip:'加载中...',
					data: {
						push_status: event.detail.value ? 1 : 2
					},
					success: res => {
						this.$xyfun.msg('修改成功')
						this.push_status = Number(res.userInfo.push_status)
					}
				})
			},
			editPhone() {
				uni.navigateTo({
					url: `/pages/user/phone`
				})
			},
			passWord() {
				uni.navigateTo({
					url: `/pages/user/password`
				})
			},

			submit() {
				// this.$xyfun.to('/pages/create');
			}
		}
	}
</script>

<style scoped lang="scss">
	.form-item {
		width: 650rpx;
		float: left;
	}
	.form-submit {
		margin: 35rpx 0 50rpx;
		width: 649rpx;
		height: 100rpx;
		border-radius: 15rpx;
		background-color: rgba(0,86,80,1);
		text-align: center;
		color: white;
		line-height: 95rpx;
		float: left;
	}
	.form-view {
		width: 570rpx;
		height: 100rpx;
		position: relative;
		padding: 0 40rpx;
		float: left;
		background-color: rgba(255,255,255,1);
		line-height: 100rpx;
		border: 1rpx solid rgba(111, 111, 111, 0.31);
		margin-bottom: 35rpx;
		border-radius: 15rpx;
		.form-text {
			float: right;
		}
		.menu-item-icon {
			float: right;
			margin-top: 24rpx;
			margin-right: -10rpx !important;
		}
		img {
			width: 50rpx;
			height: 50rpx;
			margin-right: 20rpx;
		}
	}
</style>